﻿using MediatR;
using W.Purchase.API.Application.Command.FinanceTypeCommand;
using W.Purchase.Repository.Interface;

namespace W.Purchase.API.Application.CommandHandler.FinanceTypeCommandHandler
{
    public class FinanceTypeRangeDeleteCommandHandler:IRequestHandler<FinanceTypeRangeDeleteCommand,int>
    {
        private readonly IFinanceTypesRepository _financeTypesRepository;
        public FinanceTypeRangeDeleteCommandHandler(IFinanceTypesRepository financeTypesRepository)
        {
            _financeTypesRepository = financeTypesRepository;
        }

        public async Task<int> Handle(FinanceTypeRangeDeleteCommand request, CancellationToken cancellationToken)
        {
            var list = await _financeTypesRepository.GetAllAsaync();
            var plist = list.Where(c => request.Ids.Contains(c.FinanceTypeId)).ToList();
            foreach (var item in plist)
            {
                item.IsDelete = true;
            }
            int n = await _financeTypesRepository.UpdateRangeAsync(plist);
            return n;
        }
    }
}
